﻿using FB.Data.Models;
using FB.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using System.Text;

namespace FB.Providers.AEInfo
{
    [Table("BASE_AEGroups", Schema = "ae")]
    public class AEGroup : FBAuditModel
    {
        [Key, Column(Order = 1)]
        public long AEID { get; set; }

        [Key, Column(Order = 2)]
        public long MasterAEID { get; set; }

    }



    [Table("BASE_AEDetails", Schema = "ae")]
    public class AEDetail : FBAuditModel, IRecordState, IPersonalInfo, IFullName
    {

        public AEDetail()
        {
            JoinHistories = new List<JoinHistory>();
            Accounts = new List<BankAccount>();
        }


        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long ID { get; set; }

        [EnumDataType(typeof(AEDetailStatus))]
        public AEDetailStatus AEStatus { get; set; }

        public RecordState RecordState { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "LastName")]
        public string LastName { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "FirstName")]
        public string FirstName { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Alias")]
        public string Alias { get; set; }

        [StringLength(256), Column("CHNName")]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "ChineseName")]
        public string ChineseName { get; set; }

        [StringLength(1)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Gender")]
        public string Gender { get; set; }

        [StringLength(256)]
        public string HKID { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Email")]
        public string Email { get; set; }

        [StringLength(32)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Tel")]
        public string Tel { get; set; }

        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Mobile")]
        public string Mobile { get; set; }

        [StringLength(32)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "SMS")]
        public string SMS { get; set; }

        [StringLength(32)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "ExtensionNo")]
        public string ExtensionNo { get; set; }

        [StringLength(512)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Addr1")]
        public string Addr1 { get; set; }

        [StringLength(512)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Addr2")]
        public string Addr2 { get; set; }


        [DataType(DataType.Date)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Onboarding")]
        public DateTime? Onboarding { get; set; }

        [DataType(DataType.Date)]
        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "TerminationDate")]
        public DateTime? TerminationDate { get; set; }

        //public int? AEType { get; set; }

        /// <summary>
        /// SFC Central Entity Number 
        /// </summary>
        [StringLength(16)]
        public string SFCCENo  { get; set; }

        public int? LocationID { get; set; }

        [Display(ResourceType = typeof(Resources.Models.AEInfo), Name = "Remarks")]
        public string Remarks { get; set; }

        [ForeignKey("LocationID")]
        public virtual Location Location { get; set; }

        [ForeignKey("AEID")]
        public virtual ICollection<JoinHistory> JoinHistories { get; set; }

        [ForeignKey("AEID")]
        public virtual ICollection<BankAccount> Accounts { get; set; }


        public virtual ICollection<AEDetail> AEMasters { get; set; }
        //public virtual AEDetail AEMaster { get; set; }
        public virtual ICollection<AEDetail> AEGroupUsers { get; set; }
        


        [NotMapped]
        public string FullName
        {
            get
            {
                var f = new StringBuilder();
                if (!string.IsNullOrEmpty(LastName)) f.AppendFormat("{0} ", LastName);
                if (!string.IsNullOrEmpty(FirstName)) f.AppendFormat("{0} ", FirstName);
                if (!string.IsNullOrEmpty(Alias)) f.AppendFormat("{0} ", Alias);
                if (!string.IsNullOrEmpty(ChineseName)) f.AppendFormat("{0} ", ChineseName);

                return f.ToString();
            }
        }

        [NotMapped]
        public string EngFullName
        {
            get
            {
                var f = new StringBuilder();
                if (!string.IsNullOrEmpty(LastName)) f.AppendFormat("{0} ", LastName);
                if (!string.IsNullOrEmpty(FirstName)) f.AppendFormat("{0} ", FirstName);
                if (!string.IsNullOrEmpty(Alias)) f.AppendFormat("{0} ", Alias);

                return f.ToString();
            }
        }

    }
 
}
